$(function () {
    //数据和图片的加载直接在页面中用beetl读取
    //init();
    //initBrews();
});

var teaId = "";

//页面初始化
//根据茶叶id获取相应图片
function init() {
    var urlParam = window.location.search;

    //截取id
    if (urlParam.indexOf("?") != -1) {
        teaId = urlParam.substr(4, urlParam.length);
        console.log(teaId);
    }

    $.ajax({
        type: 'GET',
        url: '/teaFile/findPicture',
        data: {'teaId': teaId},
        dataType: 'json',
        success: function (result) {
            if (result != null && result.zyPictureList.length != 0) {
                for (var i = 0, len = result.zyPictureList.length; i < len; i++) {
                    if (result.zyPictureList[i].label == "茶叶介绍") {
                        $(".teaIntroduce" + [i]).attr('src', result.zyPictureList[i].src);
                    } else if (result.zyPictureList[i].label == "品牌介绍") {
                        $("#branIntroduce" + [i]).attr('src', result.zyPictureList[i].src);
                        $("#branIntroduce_a_" + [i]).attr('src', result.zyPictureList[i].src);
                    } else if (result.zyPictureList[i].label == "产品包装") {
                        $("#packing" + [i]).attr('src', result.zyPictureList[i].src);
                    }

                }
            }
        },
        error: function (result) {
            console.log("请求失败：" + result)
        }
    });
}

function initBrews() {
    $.ajax({
        type: 'GET',
        url: '/teaFile/findBrews',
        data: {'teaId': teaId},
        dataType: 'json',
        success: function (result) {
            // if (result != null && result.brewsSequenceList.length != 0) {
            //     for (var i = 0, len = result.brewsSequenceList.length; i < len; i++) {
            //         $("#brewsWay" + [i]).attr('src', "/static/img/201801/" + result.brewsSequenceList[i].saveName);
            //     }
            // }
            for (var i = 0, len = result.zyPictureList.length; i < len; i++) {
                $("#brewsWay" + [result.zyPictureList]).attr('src', result.zyPictureList[i].src);
            }
        },
        error: function (result) {
            console.log("请求失败：" + result)
        }
    });
}

function initOld() {
    var urlParam = window.location.search;
    var teaId = "";
    //截取id
    if (urlParam.indexOf("?") != -1) {
        teaId = urlParam.substr(4, urlParam.length);
        console.log(teaId);
    }

    $.ajax({
        type: 'GET',
        url: '/teaFile/findPicture',
        data: {'teaId': teaId},
        dataType: 'json',
        success: function (result) {

            if (result != null && result.zyPictureList.length != 0) {

                for (var i = 0, len = result.zyPictureList.length; i < len; i++) {
                    if (result.zyPictureList[i].label == "茶叶介绍") {
                        $(".teaIntroduce" + [i]).attr('src', "/static/img/tea/" + result.zyPictureList[i].saveName);
                    } else if (result.zyPictureList[i].label == "冲泡方式") {
                        $("#brewsWay" + [i]).attr('src', "/static/img/brews/" + result.zyPictureList[i].saveName);
                    } else if (result.zyPictureList[i].label == "品牌介绍") {
                        $("#branIntroduce" + [i]).attr('src', "/static/img/brand/" + result.zyPictureList[i].saveName);
                        $("#branIntroduce_a_" + [i]).attr('src', "/static/img/brand/" + result.zyPictureList[i].saveName);
                    } else if (result.zyPictureList[i].label == "产品包装") {
                        $("#packing" + [i]).attr('src', "/static/img/packing/" + result.zyPictureList[i].saveName);
                    }

                }
            }
        },
        error: function (result) {
            console.log("请求失败：" + result)
        }
    });

}